// pages/ucenter/ucenter.js
const app = getApp()
var get_user;var che_user;

Page({

  /**
   * 页面的初始数据
   */
  data: {
    userInfo: {},
    hasUserInfo: false,
    canIUse: wx.canIUse('button.open-type.getUserInfo'),
    com_list:[
      {name:'已中标',img:'/image/u_2.png',type:1},
      {name:'代取件',img:'/image/u_4.png',type:2},
      {name:'运输中',img:'/image/u_5.png',type:3},
      {name:'待确认',img:'/image/u_6.png',type:4},
      {name:'已送达',img:'/image/u_7.png',type:5}
    ],
    ren_list:[
      {name:'竞价中',img:'/image/u_2.png',type:1},
      {name:'待付款',img:'/image/u_3.png',type:2},
      {name:'待取件',img:'/image/u_4.png',type:3},
      {name:'运输中',img:'/image/u_5.png',type:4},
      {name:'待确认',img:'/image/u_6.png',type:5},
      {name:'待评价',img:'/image/u_7.png',type:6}
    ],
    info:{},
    role_id:0,
    headurl_image:null,
    nickname:'',
    mobile:'',
    vip:0,
    vip_y:0,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    get_user = app.data.ucenter_url + 'get_user';
    che_user = app.data.ucenter_url + 'che_user';
    
  },
  sordertap:function(e){
    var type = e.currentTarget.dataset.type;
    wx.navigateTo({
      url: '/pages/u_Sorder/u_Sorder?type='+type,
    })
  },
  rordertap:function(e){
    var type = e.currentTarget.dataset.type;
    wx.navigateTo({
      url: '/pages/u_Rorder/u_Rorder?type='+type,
    })
  },
  sztap:function(e){
    wx.navigateTo({
      url: '/pages/u_sz/u_sz',
    })
  },
  bagtap:function(e){
    wx.navigateTo({
      url: '/pages/u_bag/u_bag',
    })
  },
  rztap:function(e){
    wx.navigateTo({
      url: '/pages/u_rz/u_rz',
    })
  },
  yrztap:function(e){
    var that = this;
    var info = that.data.info;
    var role_id = info.role_id;
    var sh_status = info.sh_status;
    if(role_id == 1 && sh_status == 0){
      wx.showModal({
        title: '提示',
        content: '保姆司机认证信息正在审核中，请耐心等待！',
        showCancel: false
      })
    }else if(role_id == 2 && sh_status == 0){
      wx.showModal({
        title: '提示',
        content: '托运公司认证信息正在审核中，请耐心等待！',
        showCancel: false
      })
    }else if(role_id == 1 && sh_status == 2){
      wx.showModal({
        title: '提示',
        content: '保姆司机认证信息被驳回请重新认证！',
        showCancel: false,
        success:function(e){
          wx.navigateTo({
            url: '/pages/u_rzDriver/u_rzDriver',
          })
        }
      })
    }else if(role_id == 2 && sh_status == 2){
      wx.showModal({
        title: '提示',
        content: '托运公司认证信息被驳回请重新认证！',
        showCancel: false,
        success:function(e){
          wx.navigateTo({
            url: '/pages/u_rzComp/u_rzComp',
          })
        }
      })
    }
  },
  yhqtap:function(e){
    wx.navigateTo({
      url: '/pages/u_yhq/u_yhq',
    })
  },
  fktap:function(e){
    wx.navigateTo({
      url: '/pages/u_fk/u_fk',
    })
  },
  tstap:function(e){
    wx.navigateTo({
      url: '/pages/u_myts/u_myts',
    })
  },
  tslisttap:function(e){
    wx.navigateTo({
      url: '/pages/u_tslist/u_tslist',
    })
  },
  pjtap:function(e){
    wx.navigateTo({
      url: '/pages/u_pj/u_pj',
    })
  },
  qhtap:function(e){
    var that = this;
    var vip = that.data.vip;
    var vip_y = that.data.vip_y;
    if(vip != 0){
      that.setData({
        vip: 0
      })
    }else{
      if(vip_y != 0){
        that.setData({
          vip: 1
        })
      }
    }
  },
  getUserInfo(e) {
    console.log(e)
    app.globalData.userInfo = e.detail.userInfo
    this.setData({
      userInfo: e.detail.userInfo,
      hasUserInfo: true
    })
  },
  getUserInfo: function (e) {
    console.log(e);
    var that = this;
    app.globalData.userInfo = e.detail.userInfo;
    var aid = wx.getStorageSync('uid');
    if (e.detail.userInfo) {
      var name = e.detail.userInfo.nickName;
      var img = e.detail.userInfo.avatarUrl;
      wx.request({
        url: che_user,
        data: {
          uid: aid,
          img: img,
          name: name
        },
        header: {
          'content-type': 'application/json'
        },
        success: function (res) {
          console.log(res.data);
          that.setData({
            headurl_image: img
          })
          that.onShow();
        }
      });
      this.setData({
        userInfo: e.detail.userInfo,
        hasUserInfo: true
      })
    }
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var that = this;
    var aid = wx.getStorageSync('uid');
    wx.request({
      url: get_user,
      data: {
        uid: aid
      },
      header: {
        'content-type': 'application/json' // 默认值
      },
      success(res) {
        console.log(res.data);
        var info = res.data.info;
        var role_id = info.role_id;
        var sh_status = info.sh_status;
        var headurl_image = info.headurl_image;
        var nickname = info.nickname;
        var mobile = info.mobile;
        var vip = 0;
        if(role_id == 1 && sh_status == 1){
          vip = 1;
        }else if(role_id == 2 && sh_status == 1){
          vip = 1;
        }else{
          vip = 0;
        }
        console.log(vip);
        that.setData({
          info:info,
          role_id:role_id,
          vip:vip,
          vip_y:vip,
          headurl_image:headurl_image,
          nickname:nickname,
          mobile:mobile,
        })
      }
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})